LCS

Implements the Longest Common Subsequence (LCS) problem consists in finding the longest subsequence common to two (or more) sequences. It differs from problems of finding common substrings: unlike substrings, subsequences are not required to occupy consecutive positions within the original sequences.

It is used by the diff utility, by Git for reconciling multiple changes, etc.

The LCS edit distance between strings \(X\) and \(Y\) is: \(\lvert X \rvert + \lvert Y \rvert - 2 \times \lvert LCS(X, Y) \rvert\)

  • \(\text{min} = 0\)

  • \(\text{max} = \lvert X \rvert + \lvert Y \rvert\).

LCS distance is equivalent to Levenshtein distance, when only insertion and deletion is allowed (no substitution), or when the cost of the substitution is the double of the cost of an insertion or deletion.

Author

solonovamax

See also

Functions

Link copied to clipboard
open override fun distance(s1: String, s2: String): Double

Compute and return the metric distance.

Link copied to clipboard
open override fun similarity(s1: String, s2: String): Double

Computes the similarity of two strings.